package com.example.zuo.mysuperwidgetdemo.ui.base;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.example.zuo.mysuperwidgetdemo.utils.ToastUtils;


/**
 * Created by ych on 2017/3/8.
 */

public abstract class BaseNewActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        saveBack(savedInstanceState);
        setContentView(bindLayout());
        bindId();
        setListener();
        init();
    }


    protected abstract int bindLayout();

    protected abstract void bindId();

    protected abstract void init();
    protected abstract void setListener();

    protected void saveBack(Bundle savedInstanceState) {
    }

    public String getText(TextView textView) {
        if (textView == null ||
                textView.getText() == null
                || textView.getText().toString() == null)
            return null;
        return textView.getText().toString();
    }

    public void setText(String str, TextView textView) {
        if (str != null)
            textView.setText(str);
    }

    public boolean isEmpty(TextView textView, String warm) {
        if (isEmpty(textView)) {
            TOT(warm);
            return true;
        } else
            return false;
    }

    public boolean isEmpty(TextView textView) {
        if (textView == null
                || TextUtils.isEmpty(textView.getText().toString()))
            return true;
        return false;
    }

    public void TOT(int str) {
        TOT(str + "");
    }

    public void TOT(String str) {
        ToastUtils.showCustomToast(this, str);
    }

    public Intent NewIntent(Class<?> c) {

        return new Intent(this, c);
    }

    public <T extends View> T getView(int viewId) {
        View view = findViewById(viewId);
        return (T) view;
    }
//    public void netErr() {
//
//        TOT(getString(R.string.neterr));
//    }
//
//    MyDialog dialog;
//
//    public void showDialog() {
//        dialog = DialogUtil.showDialog(this);
//        dialog.show();
//    }
//
//    public void disDialog(boolean isS) {
//        if (!isS)
//            netErr();
//        if (dialog != null)
//            dialog.dismiss();
//    }
//
//    public void disDialog() {
//        if (dialog != null)
//            dialog.dismiss();
//
//    }

}
